package controllers

import play.api.mvc._
import play.api.Play.current


object Application extends Controller {

  def index = Action {
    //Result(header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")), body = Enumerator( outString.getBytes()))
    //Result(header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")), body = views.xml.boundary(<name> outString </name>))
    Ok(views.html.index("Welcome"))
    //Ok(views.xml.boundary(<name> $outString </name>)).as("application/vnd.google-earth.kml+xml")
  }

}

import akka.actor._
import sys.process._

object MyWebSocketActor {
  def props(out: ActorRef) = Props(new MyWebSocketActor(out))
}

class MyWebSocketActor(out: ActorRef) extends Actor {
  
  def receive = {
    case "fortune" =>
      out ! ("fortune".!!)
    case msg: String =>
      out ! ("I have got ur msg: " + msg)
  }
}

object WsApplication extends Controller {
  def socket = WebSocket.acceptWithActor[String, String] { request => out =>
    MyWebSocketActor.props(out)
  }
  def index = Action {
    //Result(header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")), body = Enumerator( outString.getBytes()))
    //Result(header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")), body = views.xml.boundary(<name> outString </name>))
    Ok(views.html.ws())
  }
}
